package com.piece.file.enums;

import com.piece.core.framework.util.collection.ArrayUtil;
import com.piece.file.client.FileClient;
import com.piece.file.client.FileClientConfig;
import com.piece.file.client.ftp.FtpFileClient;
import com.piece.file.client.ftp.FtpFileClientConfig;
import com.piece.file.client.local.LocalFileClient;
import com.piece.file.client.local.LocalFileClientConfig;
import com.piece.file.client.mongo.MongoFileClient;
import com.piece.file.client.mongo.MongoFileClientConfig;
import com.piece.file.client.s3.S3FileClient;
import com.piece.file.client.s3.S3FileClientConfig;
import com.piece.file.client.sftp.SftpFileClient;
import com.piece.file.client.sftp.SftpFileClientConfig;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum FileStorageType {

    NATIVE("native", LocalFileClientConfig.class, LocalFileClient.class),
    FTP("ftp", FtpFileClientConfig.class, FtpFileClient.class),
    SFTP("sftp", SftpFileClientConfig.class, SftpFileClient.class),
    MONGO("mongo", MongoFileClientConfig.class, MongoFileClient.class),
    S3("s3", S3FileClientConfig.class, S3FileClient.class);

    /**
     * 存储器
     */
    private final String name;

    /**
     * 配置类
     */
    private final Class<? extends FileClientConfig> configClass;

    /**
     * 客户端类
     */
    private final Class<? extends FileClient> clientClass;

    public static FileStorageType getByStorage(String name) {
        return ArrayUtil.firstMatch(o -> o.getName().equalsIgnoreCase(name), values());
    }
}
